$(document).ready(function(){
	
	$.ajax({
  		type: "post",
 		url: "wsq/SchedBase_getAllDuty.action",
  		success:function(data){
  			$.each(data.tbDuties,function(i,n){
  				$("<option value="+n.duId+">"+n.duId+"</option>").appendTo('#duId');
			});
  		}
	});
	
	$.ajax({
  		type: "post",
 		url: "wsq/SchedBase_getAllDShift.action",
  		success:function(data){
  			$.each(data.tbDetailShifts,function(i,n){
  				$("<option value="+n.dsName+">"+n.dsName+"</option>").appendTo('#dsName');
			});
  		}
	});	
	
	
	$.ajax({
  		type: "post",
 		url: "wsq/SchedBase_getAllUser.action",
  		success:function(data){
  			$.each(data.tbUsers,function(i,n){
  				$("<option value="+n.UId+">"+n.UName+"</option>").appendTo('#UId');
			});
  		}
	});
	
	/*
	 * 8.20修改
	 * */	
	/*$('#duId').click(function(){
		 var duId=$('#duId option:selected').val();		
		
		 $.ajax({
		 
  			type: "post",
 			url: "wsq/SchedBase_getDShift.action",
 			data:{
 				  "duId1":duId
 				 },
  			success:function(data){
		  			$.each(data.tbDetailShifts,function(i,n){
		  				$("<option value="+n.dsName+">"+n.dsName+"</option>").appendTo('#dsName');
					});
		  		}
		 });
	});*/
	
	$('#ADD_SCHED').click(function(){
		var duId=$('#duId option:selected').val();
		var dsName=$('#dsName option:selected').val();
		var UId=$('#UId option:selected').val();
		var scTime=$('#scTime').val();		
		
		if(duId!==null && duId.length!==0 && dsName!==null &&  dsName.length!==0 &&
		UId!==null && UId.length!==0 && scTime!==null &&  scTime.length!==0){
		
		 $.ajax({
		 
  			type: "post",
 			url: "wsq/AddSched_saveSched.action",
 			data:{
 				  "duId1":duId,"dsName1":dsName,"UId1":UId,"scTime":scTime
 				 },
  			success:showData
		 });
		}else{
			alert("带*号的必填！");
		}
	});
	
	function showData(data){
		if(data.ajaxRST=='1'){
			alert("保存成功");
			$('#tabFrame',window.parent.document).attr('src','wsq/paiban1.jsp');
		}else{
			alert("save sched failed!");
		}
	}
	
	$('#reset_SCHED').click(function(){
		$('#tabFrame',window.parent.document).attr('src','wsq/AddSched.jsp');
	});
	
	$('#RETURN_SCHED').click(function(){
		$('#tabFrame',window.parent.document).attr('src','wsq/paiban1.jsp');
	});
	
	
	/*$("#addDutyForm").validate({
		submitHandler: function(form){   //表单提交句柄,为一回调函数，带一个参数：form  
           form.submit();   //提交表单  
      // alert(88);
	},
		rules: {
        	'duty.tbWorkDay.wdId':'required',
        	'duty.tbShiftType.psId':'required',
        	'duty.duName':'required',
        	'duty.duPhone':{
        		reuqierd:false,
        		number: true 
            }			
		},
		messages: {
			'duty.tbWorkDay.wdId':"*必须选",
			'duty.tbShiftType.psId':"*必须选",
			'duty.duName':"*",
			'duty.duPhone':"数字"
		}
	});
	*/
});